package com.info.service.impl;

import com.common.PagedResult;
import com.info.InfoQueryCondition;
import com.info.domain.Info;
import com.info.repository.InfoRepository;
import com.info.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by sola on 2018/1/15.
 */
@Service
@Transactional
@CacheConfig(cacheNames = "Info")
public class InfoServciceImpl implements InfoService {

    private InfoRepository infoRepository;

    @Autowired
    public InfoServciceImpl(InfoRepository infoRepository) {
        this.infoRepository = infoRepository;
    }

    @Override
    @Cacheable
    public PagedResult<Info> findAll(InfoQueryCondition condition) {
        Page<Info> page = infoRepository.findAll(condition);

        return new PagedResult<Info>(page.getTotalElements(),page.getContent());
    }
}
